﻿using System;
using System.Collections.Generic;

namespace POP.Mime.Traverse
{
	// An abstract class that implements the MergeLeafAnswers method.
	// The method simply returns the union of all answers from the leaves.
	public abstract class MultipleMessagePartFinder : AnswerMessageTraverser<List<MessagePart>>
	{
		protected override List<MessagePart> MergeLeafAnswers(List<List<MessagePart>> leafAnswers)
		{
			if(leafAnswers == null)
				throw new ArgumentNullException("leafAnswers");

			// We simply create a list with all the answer generated from the leaves
			List<MessagePart> mergedResults = new List<MessagePart>();

			foreach (List<MessagePart> leafAnswer in leafAnswers)
			{
				mergedResults.AddRange(leafAnswer);
			}

			return mergedResults;
		}
	}
}